﻿using System;
using System.Data;
using ContractManagementSystem.DataAccessLayer;
using ContractManagementSystem.EntityObjects;

namespace ContractManagementSystem.BusinessLogicLayer
{
    public static class AdministrationUtilityLogic
    {
        // Make authentication on account
        public static AccountEntity Authenticate(string userName, string password)
        {
            var accountEntity = AccountDao.Authenticate(userName, password);

            return accountEntity;
        }

        //// List list of active accounts (On authorization)
        //public static DataTable ListAccount(int roleId, string userName, string status)
        //{
        //    return AccountDao.ListAccount(roleId, userName, status);
        //}

         // Insert an account
        public static string AddNewAccount(AccountEntity accountEntity)
        {
            return AccountDao.AddNewAccount(accountEntity);
        }

        //// Update an account
        //public static string UpdateAccount(AccountEntity accountEntity)
        //{
        //    return AccountDao.UpdateAccount(accountEntity);
        //}

        //// Delete an account
        //public static string DeleteAccount(string userName)
        //{
        //    return AccountDao.DeleteAccount(userName);
        //}

        //// Find accounts
        //public static DataTable FindAccount(AccountEntity accountEntity, int findingOptions)
        //{
        //    return AccountDao.FindAccount(accountEntity, findingOptions);
        //}

        // View details about an account
        public static AccountEntity ViewAccountDetail(string userName)
        {
            return AccountDao.ViewAccountDetail(userName);
        }

        // Get automatically generated user name
        public static string AutoUserName(string originalValue)
        {
            var unsignUserName = CommonLogic.CreateAutoString(originalValue);

            return AccountDao.AutoUserName(unsignUserName);
        }

        // Get random password
        public static string RandomPassword(int length)
        {
            var chars = "$%#@*abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            var password = string.Empty;
            var random = new Random();

            for (var i = 0; i < length; i++)
            {
                var x = random.Next(1, chars.Length);

                // Don't Allow Repetation of Characters
                if (!password.Contains(chars.GetValue(x).ToString()))
                    password += chars.GetValue(x);
                else
                    i--;
            }
            return password;
        }
    }
}
